package com.it.a04udpdemo3;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.Scanner;

public class SendMessageDemo {
    public static void main(String[] args) throws IOException {
        /*
        组播发送端代码
         */
        //创建对象MulticastSocket对象
        MulticastSocket ms = new MulticastSocket();
        //打包数据
        String str = "Hello World";
        byte[] data = str.getBytes();
        InetAddress address = InetAddress.getByName("224.0.0.1");
        int port = 10000;
        DatagramPacket dp = new DatagramPacket(data, data.length, address, port);
        ms.send(dp);
        //释放资源
        ms.close();
    }
}
